package com.controller;


import com.alibaba.fastjson.JSON;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.stream.Collectors;

@WebServlet("/info/*")
public class InfoServlet extends HttpServlet {
    private final InfoController handler = new InfoController();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String payload = req.getReader().lines().collect(Collectors.joining());
        System.out.println("请求载荷是：" + payload);

        String respJson = handler.handle(payload);

        resp.getWriter().write(JSON.toJSONString(respJson));
    }
}
